<template>
  <card-box>
    <div class="flexLeftSon5">
      <img
        src="@/assets/images/canvsimage/performance_icon.png"
        class="performance"
      />
      <div class="sonFlex">
        <p class="endVal">
          <count-to
            :startVal="0"
            :endVal="Number(flesLeftData.amount)"
            :decimals="2"
            :duration="3000"
          >
          </count-to>
        </p>
        <div class="sonFlexSon1">
          <p class="title">{{ homeFlexRight.title }}</p>
          <p class="unit">{{ flesLeftData.suffix }}</p>
        </div>
      </div>
    </div>
  </card-box>
</template>

<script setup lang="ts">
import { CountTo } from 'vue3-count-to'
import { storeToRefs } from 'pinia'
import { reactive, watch, ref } from 'vue'
import { useHomeStore } from '@/stores/module/home'
const homeStore = useHomeStore() // 创建store实例
const { homeFlexRight } = storeToRefs(homeStore)

const components = {
  CountTo,
}
const flesLeftData = reactive({
  amount: Number(homeFlexRight.value.amount),
  suffix: homeFlexRight.value.suffix,
})

watch(
  () => homeFlexRight.value,
  () => {
    // 重新赋值
    flesLeftData.amount = Number(homeFlexRight.value.amount)
    flesLeftData.suffix = homeFlexRight.value.suffix
  },
  { deep: true }
)
</script>

<style lang="scss" scoped>
.flexLeftSon5 {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 100px;
  .performance {
    width: 60px;
    height: 50px;
    margin-right: 8px;
  }

  .sonFlex {
    display: flex;
    flex-direction: column;

    .endVal {
      color: #ed5660;
      font-size: 20px;
      margin-bottom: 8px;
      margin-top: 5px;
    }

    .sonFlexSon1 {
      display: flex;

      .title {
        font-size: 12px;
        color: #ffffff;
        margin-right: 3.2px;
      }

      .unit {
        font-size: 12px;

        color: #5df5f3;
      }
    }
  }
}
</style>
